package com.example.filter;

import com.example.config.FilterStatusConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Description
 * ...
 * DATE 2017/11/9.
 *
 * @author Mr. Chun.
 */
@WebFilter
@Order(1)
public class FirstFilter implements Filter {

    private static final Logger logger = LoggerFactory.getLogger(FirstFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        if (FilterStatusConfig.useFirstFilter) {
            logger.info("FirstFilter => doFilter");
        }
        filterChain.doFilter(request, response);
        return;
    }

    @Override
    public void destroy() {

    }
}
